package com.wbao.dianniu.adapter;

import java.util.ArrayList;
import java.util.List;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.wbao.dianniu.R;
import com.wbao.dianniu.data.RecruitListData;

/**
 * 岗位列表（公司招聘和简历投递）
 * 
 * @author yejianjun
 *
 */
public class RecruitListAdapter extends BaseAdapter {
	private LayoutInflater mInflater;
	private List<RecruitListData> mList;

	public RecruitListAdapter(Context context) {
		mInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
		if(null == mList){
			mList = new ArrayList<RecruitListData>();
		}
	}
	
	public void addData(List<RecruitListData> list){
		if(null == list)
			return;
		for (int i = 0; i < list.size(); i++) {
			mList.add(list.get(i));
		}
	}
	
	public void setData(List<RecruitListData> list) {
		mList = list;
	}
	
	public void clear(){
		mList.clear();
		notifyDataSetChanged();
	}
	public List<RecruitListData> getList(){
		return mList;
	}
	
	@Override
	public int getCount() {
		if (null == mList)
			return 0;
		else
			return mList.size();
	}

	@Override
	public Object getItem(int position) {
		return mList.get(position);
	}

	@Override
	public long getItemId(int position) {
		return 0;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		GridHolder holder;
		if (convertView == null) {
			convertView = mInflater.inflate(R.layout.recruit_list_item, null);   
			holder = new GridHolder();
			holder.postTV =  (TextView)convertView.findViewById(R.id.recruit_list_job);
			holder.salaryTV =  (TextView)convertView.findViewById(R.id.recruit_list_salary);
			holder.educationTV =  (TextView)convertView.findViewById(R.id.recruit_list_item_education);
			holder.experienceTV =  (TextView)convertView.findViewById(R.id.recruit_list_item_experience);
			holder.tryoutTV =  (TextView)convertView.findViewById(R.id.recruit_list_tryout);
			holder.areaTV =  (TextView)convertView.findViewById(R.id.recruit_list_area);
			convertView.setTag(holder); 
		}else{
			holder = (GridHolder) convertView.getTag();
		}
		RecruitListData data = mList.get(position);
		if(null != data){
			holder.postTV.setText(data.getPost() == null ? "": data.getPost());
			holder.salaryTV.setText(data.getSalary()==null ? "" : "" + data.getSalary());
			holder.educationTV.setText(data.getEducation() == null ? "": data.getEducation());
			holder.experienceTV.setText(data.getExperience() == null ? "": data.getExperience());
			holder.tryoutTV.setText(data.getTryout() == null ? "": data.getTryout());
			holder.areaTV.setText(data.getAddress() == null ? "":"" + data.getAddress());
		}
		return convertView;
	}

	public class GridHolder {
		public TextView postTV;
		public TextView salaryTV;
		public TextView educationTV;
		public TextView experienceTV;
		public TextView tryoutTV;
		public TextView areaTV;
	}

}
